package com.example.pos_terminal;

import android.annotation.SuppressLint;
import android.content.Context;
import android.hardware.display.DisplayManager;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
import android.webkit.JavascriptInterface;

public class ScreenDisplay {
    private Context context;
    private MainActivity mainActivity;

    public ScreenDisplay(Context context,MainActivity mainActivity) {
        this.context = context;
        this.mainActivity = mainActivity;

    }
    @JavascriptInterface
    public void exit(boolean isOk){
        //强制退出
        if (isOk){
            mainActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        }else{
            mainActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        }
    }
    @JavascriptInterface
    public void setCustomerProductList(String url) {
        DisplayManager displayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE);
        Display[] displays = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
        if (displays.length > 1) {
            return;
        } else {
            Display display = displays[0];

            HelpHandPresentation helpHandPresentation = new HelpHandPresentation(context, display,null);
            // Presentation differentDislay = new DifferentDislay(this, display);

            helpHandPresentation.progressChange(url);
            //helpHandPresentation.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
            if (!mainActivity.isFinishing()) {

                helpHandPresentation.show();
            }

        }

    }
}
